package com.ourteam.product.ui.dao.impl;

import com.ourteam.product.ui.dao.IProductUITreeNodeBuilderDAO;
import com.ourteam.product.ui.dao.ProductUITreeNodeBuilder;
import com.ourteam.product.ui.dao.ProductUITreeNodeBuilderDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-12-14 15:15:19 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractProductUITreeNodeBuilderDAOJdbcImpl extends AbstractSpringDAO
    implements IProductUITreeNodeBuilderDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {Id, NodeId, Code, NodeBuilder, Status, Remarks, SortIndex};

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.NodeId,
        _DataObjectProperty.Code,
        _DataObjectProperty.NodeBuilder,
        _DataObjectProperty.Status,
        _DataObjectProperty.Remarks,
        _DataObjectProperty.SortIndex
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<ProductUITreeNodeBuilder, ProductUITreeNodeBuilderDAOQueryBean>
      daoHelper;

  public AbstractProductUITreeNodeBuilderDAOJdbcImpl() {
    super();
    daoHelper =
        new DataAccessObjectHelper<ProductUITreeNodeBuilder, ProductUITreeNodeBuilderDAOQueryBean>(
            this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aProductUITreeNodeBuilder
   * @throws Exception
   */
  public boolean checkIsUnique(ProductUITreeNodeBuilder aProductUITreeNodeBuilder)
      throws Exception {

    if (aProductUITreeNodeBuilder == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aProductUITreeNodeBuilder.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aProductUITreeNodeBuilder
   * @throws Exception
   */
  public void insert(ProductUITreeNodeBuilder aProductUITreeNodeBuilder) throws Exception {

    super.doInsert(aProductUITreeNodeBuilder);
  }

  /**
   * Batch Insert Datas
   *
   * @param aProductUITreeNodeBuilder
   * @throws Exception
   */
  public void batchInsert(ProductUITreeNodeBuilder[] aProductUITreeNodeBuilders) throws Exception {

    super.doBatchInsert(aProductUITreeNodeBuilders);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(ProductUITreeNodeBuilderDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(ProductUITreeNodeBuilder aProductUITreeNodeBuilder) throws Exception {

    delete(aProductUITreeNodeBuilder.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aProductUITreeNodeBuilder
   * @throws Exception
   */
  public void update(ProductUITreeNodeBuilder aProductUITreeNodeBuilder) throws Exception {

    if (aProductUITreeNodeBuilder.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aProductUITreeNodeBuilder);

    ProductUITreeNodeBuilder tempObj = findById(aProductUITreeNodeBuilder.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aProductUITreeNodeBuilder, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aProductUITreeNodeBuilders[]
   * @throws Exception
   */
  public void batchUpdate(ProductUITreeNodeBuilder[] aProductUITreeNodeBuilders) throws Exception {

    super.doBatchUpdate(aProductUITreeNodeBuilders);
  }

  /**
   * Update Data By Condictions
   *
   * @param aProductUITreeNodeBuilder
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(
      ProductUITreeNodeBuilder aProductUITreeNodeBuilder,
      ProductUITreeNodeBuilderDAOQueryBean aQueryBean)
      throws Exception {

    super.doUpdateByQuery(aProductUITreeNodeBuilder, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(ProductUITreeNodeBuilderDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(ProductUITreeNodeBuilder aProductUITreeNodeBuilder)
      throws Exception {

    if (aProductUITreeNodeBuilder.getCode() == null) {
      throw new Exception("The ProductUITreeNodeBuilder.code value is not allow NULL");
    }

    if (aProductUITreeNodeBuilder.getNodeBuilder() == null) {
      throw new Exception("The ProductUITreeNodeBuilder.nodeBuilder value is not allow NULL");
    }

    if (aProductUITreeNodeBuilder.getStatus() == null) {
      throw new Exception("The ProductUITreeNodeBuilder.status value is not allow NULL");
    }

    if (aProductUITreeNodeBuilder.getRemarks() == null) {
      throw new Exception("The ProductUITreeNodeBuilder.remarks value is not allow NULL");
    }
  }

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public ProductUITreeNodeBuilder findById(final long id) throws Exception {

    ProductUITreeNodeBuilderDAOQueryBean queryBean = new ProductUITreeNodeBuilderDAOQueryBean();

    ProductUITreeNodeBuilderDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    ProductUITreeNodeBuilder[] ProductUITreeNodeBuilders = query(queryBean);

    if (ProductUITreeNodeBuilders.length == 0) {
      return null;
    } else {
      return ProductUITreeNodeBuilders[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return ProductUITreeNodeBuilder[]
   * @throws Exception
   */
  public ProductUITreeNodeBuilder[] query(ProductUITreeNodeBuilderDAOQueryBean queryBean)
      throws Exception {

    List result = super.doQuery(queryBean, new JdbcProductUITreeNodeBuilderRowMapper());

    return (ProductUITreeNodeBuilder[]) result.toArray(new ProductUITreeNodeBuilder[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(ProductUITreeNodeBuilderDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(ProductUITreeNodeBuilderDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(
      ProductUITreeNodeBuilder[] aProductUITreeNodeBuilders,
      ProductUITreeNodeBuilderDAOQueryBean queryBean)
      throws Exception {
    daoHelper.synchronize(aProductUITreeNodeBuilders, queryBean);
  }

  public void synchronize(
      ProductUITreeNodeBuilder[] aProductUITreeNodeBuilders,
      ProductUITreeNodeBuilderDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<ProductUITreeNodeBuilder> callBack)
      throws Exception {
    daoHelper.synchronize(aProductUITreeNodeBuilders, queryBean, callBack);
  }

  public static class JdbcProductUITreeNodeBuilderRowMapper
      implements RowMapper<ProductUITreeNodeBuilder> {

    public ProductUITreeNodeBuilder mapRow(ResultSet resultSet, int arg1) throws SQLException {
      ProductUITreeNodeBuilder object = new ProductUITreeNodeBuilder();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object nodeId = null;

        nodeId = resultSet.getObject(columnIndex++);

        object.setNodeIdNull(resultSet.getBoolean(columnIndex++));

        if (nodeId != null) {

          setBeanValue(object, _DataObjectProperty.NodeId, nodeId);
        }

        Object code = null;

        code = resultSet.getObject(columnIndex++);

        object.setCodeNull(resultSet.getBoolean(columnIndex++));

        if (code != null) {

          setBeanValue(object, _DataObjectProperty.Code, code);
        }

        Object nodeBuilder = null;

        nodeBuilder = resultSet.getObject(columnIndex++);

        object.setNodeBuilderNull(resultSet.getBoolean(columnIndex++));

        if (nodeBuilder != null) {

          setBeanValue(object, _DataObjectProperty.NodeBuilder, nodeBuilder);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object remarks = null;

        remarks = resultSet.getObject(columnIndex++);

        object.setRemarksNull(resultSet.getBoolean(columnIndex++));

        if (remarks != null) {

          setBeanValue(object, _DataObjectProperty.Remarks, remarks);
        }

        Object sortIndex = null;

        sortIndex = resultSet.getObject(columnIndex++);

        object.setSortIndexNull(resultSet.getBoolean(columnIndex++));

        if (sortIndex != null) {

          setBeanValue(object, _DataObjectProperty.SortIndex, sortIndex);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
